package com.newtouch.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.newtouch.bean.NoticeInfo;
import com.newtouch.rabbbitmq.Sender;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.logging.Logger;

/**
 * Created by Administrator on 2017/8/25.
 */
@RestController
public class ResolveDemo {
    @Autowired
    private Sender sender;
    private final Logger log = Logger.getLogger("ResolveDemo.class");
    @RequestMapping(value = "/paramResolve")
    public  void paramResolve(@RequestBody String param){

        JSONObject dataJson = null;
        NoticeInfo noticeInfo = new NoticeInfo();
            if(param != null){
                try{
                    dataJson= JSON.parseObject(param);
                }catch (JSONException e){
                    e.printStackTrace();
                }
                if(dataJson != null){
                 List list = (List)dataJson.get("alerts");
                 if(list != null){
                     Map map = (Map)list.get(0);
                     if(map != null){
                          Map subMap = (Map)map.get("annotations");
                          if(subMap != null){
                              noticeInfo.setNotice_content(subMap.get("description").toString());
                              noticeInfo.setNotice_title(subMap.get("summary").toString());
                              //sender.send(noticeInfo);
                          }
                     }
                 }
                }
            }
        log.info("接收到的参数是："+dataJson);

    }
}
